package com.gin.kotlin.gf2gamecommunity.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.gin.kotlin.gf2gamecommunity.app.App
import com.gin.kotlin.gf2gamecommunity.base.livedata.CachedLiveData
import com.gin.kotlin.gf2gamecommunity.base.livedata.CachedPagingData
import com.gin.kotlin.gf2gamecommunity.pagingsource.SearchTopicPagingSource
import com.gin.kotlin.gf2gamecommunity.pagingsource.SearchUserPagingSource
import com.gin.kotlin.response.ListData
import com.gin.kotlin.response.Res
import com.gin.kotlin.response.search.FoundUser
import com.gin.kotlin.response.search.HotWord
import com.gin.kotlin.response.topic.TopicInfo

/**
 * 搜索ViewModel
 * @property hotWord 热搜词
 * @property topic 搜索主题
 * @property user 搜索用户
 * @constructor
 */
class SearchViewModel : ViewModel() {
    val hotWord = CachedLiveData<Res<ListData<HotWord>>, List<HotWord>>(
        requestMethod = { App.INSTANCE.api.searchApi.getHotWord() },
        bodyTransform = { it.data?.list },
    )

    val topic = CachedPagingData<TopicInfo, String>(scope = viewModelScope) { SearchTopicPagingSource(it) }
    val user = CachedPagingData<FoundUser, String>(scope = viewModelScope) { SearchUserPagingSource(it) }


    companion object {
        private val TAG = SearchViewModel::class.java.simpleName
    }
}